package smartclass.adapter;

import java.util.ArrayList;

import smartclass.entity.SpinnerItem;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jeremyfeinstein.slidingmenu.example.R;

public class SpinnerItemAdapter extends ArrayAdapter<SpinnerItem> {

	private Context context;
	private int resource;
	private ArrayList<SpinnerItem> array;

	public SpinnerItemAdapter(Context context, int resource,
			ArrayList<SpinnerItem> array) {
		super(context, resource, array);
		this.context = context;
		this.resource = resource;
		this.array = array;
		// TODO Auto-generated constructor stub
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(context);
			convertView = inflater.inflate(resource, parent, false);
		}
		ImageView iconimg = (ImageView) convertView
				.findViewById(R.id.iconspiner);
		TextView tvTitle = (TextView) convertView.findViewById(R.id.tvSpinner);
		iconimg.setImageResource(array.get(position).getIcon());
		iconimg.setVisibility(View.GONE);
		tvTitle.setText(array.get(position).getTitle());

		return convertView;

	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			LayoutInflater mInflater = (LayoutInflater) context
					.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			convertView = mInflater.inflate(resource, null);
		}

		ImageView imgIcon = (ImageView) convertView
				.findViewById(R.id.iconspiner);
		TextView txtTitle = (TextView) convertView.findViewById(R.id.tvSpinner);

		imgIcon.setImageResource(array.get(position).getIcon());
		txtTitle.setText(array.get(position).getTitle());
		return convertView;
	}

}
